<template>
  <div class="login">
    <div class="mylogo">
      <img src="../assets/img/logo.png" alt="" />
    </div>
    <!-- 填写登录 -->
    <div class="wrapper">
      <div class="title">
        <div class="ringUp" :class="{ active: msg == 0 }" @click="toggle()">
          <span>账号登录</span>
        </div>
        <div class="account" :class="{ active: msg == 1 }" @click="change()">
          <span>注册账号</span>
        </div>
      </div>
      <div class="message">
        <div class="phone">
          <span class="bi bi-phone"></span>
          <input type="text" v-model="username" placeholder="请输入手机号码" />
        </div>
        <div class="password">
          <span class="bi bi-lock"></span>
          <input
            type="password"
            v-if="!isEye"
            v-model="password"
            placeholder="请输入登录密码"
          />
          <input
            type="text"
            v-if="isEye"
            v-model="password"
            placeholder="请输入登录密码"
          />
          <div class="eye-icon" @click="btnPass">
            <span v-if="!isEye" class="bi bi-eye-slash"></span>
            <span v-if="isEye" class="bi bi-eye"></span>
          </div>
        </div>
      </div>
      <div class="loginTo" @click="logoTo">
        <span>{{ text }}</span>
      </div>
      <div class="forgot">
        <span>忘记密码?</span>
      </div>
    </div>
  </div>
</template>

<script>
import { post } from "@/utils/http";

export default {
  data() {
    return {
      msg: 0,
      text: "登录",
      isEye: false,
      username: "",
      password: "",
    };
  },
  methods: {
    toggle() {
      this.msg = 0;
      this.text = "登录";
    },
    change() {
      this.msg = 1;
      this.text = "注册";
    },
    btnPass() {
      this.isEye = !this.isEye;
    },
    init() {
      let obj = {};
      obj.account = this.username;
      obj.password = this.password;
      console.log(obj);

      post("/api/login", obj).then(
        (response) => {
          let res = response.data;
          // console.log( res);
          if (res.status == 200) {
            let data = res.data;
            //  console.log(data);
            sessionStorage.setItem("token", data.token);
            this.$router;
          } else {
            alert("账号或密码错误,请重新输入!");
          }
        },
        (error) => {
          console.log(error);
        }
      );
    },
    logoTo() {
      this.init();
      this.username = "";
      this.password = "";
      let data = sessionStorage.getItem("token");
      // console.log(data, 666);
      if (data !== null) {
        // console.log(data, 444);
        this.$router.push({ path: "/person" });
      } else {
        console.log("账号或密码错误,请重新输入!");
      }
    },
  },
  created() {
    let data = sessionStorage.getItem("token");
    // console.log(data, 666);
    if (data !== null) {
      // console.log(data, 444);
      this.$router.push({ path: "/person" });
    } else {
      console.log("账号或密码错误,请重新输入!");
    }
  },
};
// 13565659698
// admin8899
</script>

<style lang="less">
body,
html {
  margin: 0px;
}
.login {
  width: 100%;
  height: 667px;
  overflow: hidden;
  background: url("../assets/img/cool-background.png");
  background-size: cover;
  background-repeat: no-repeat;
}
.mylogo {
  width: 200px;
  height: 120px;
  border-radius: 50%;
  margin-top: 50px;
  margin-left: 100px;
  img {
    width: 100%;
    height: 100%;
    display: block;
  }
}
.wrapper {
  width: 320px;
  height: 300px;
  background: #fff;
  margin-left: 30px;
  margin-top: 30px;
  border-radius: 10px;
  .title {
    width: 100%;
    height: 60px;
    line-height: 50px;
    font-size: 22px;
    .ringUp {
      width: 90px;
      height: 50px;
      display: inline-block;
      margin-left: 50px;
    }
    .account {
      width: 90px;
      height: 50px;
      margin-left: 45px;
      display: inline-block;
    }
    .active {
      border-bottom: 3px solid #ea7ad7;
    }
  }
  .message {
    width: 100%;
    height: 130px;
    .phone {
      width: 90%;
      height: 50px;
      margin-left: 10px;
      border-bottom: 1px solid #ccc;
      span {
        font-size: 25px;
        padding-left: 10px;
        padding-right: 10px;
        color: #666;
      }
      input {
        width: 220px;
        height: 45px;
        outline: none;
        font-size: 18px;
        border: transparent;
        padding-left: 15px;
      }
    }
    .password {
      width: 90%;
      height: 50px;
      padding-top: 20px;
      margin-left: 10px;
      border-bottom: 1px solid #ccc;
      span {
        font-size: 25px;
        padding-left: 10px;
        padding-right: 10px;
        color: #666;
      }
      input {
        width: 180px;
        height: 45px;
        outline: none;
        font-size: 18px;
        border: transparent;
        padding-left: 15px;
      }
    }
  }
  .eye-icon {
    display: inline-block;
  }

  .loginTo {
    width: 250px;
    height: 45px;
    border-radius: 50px;
    text-align: center;
    line-height: 45px;
    font-size: 18px;
    color: #fff;
    margin: 10px auto 0px;
    background: linear-gradient(to left, #d5a3f0, #ee609c);
  }
  .forgot {
    width: 100px;
    height: 30px;
    margin-left: 220px;
    margin-top: 10px;
    font-size: 16px;
    color: #666;
  }
}
</style>